package com.todofun.common.util;

import java.util.Date;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.time.DateFormatUtils;

public class CommonUtil {
	public static final String CURRENT_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
	public static final String CURRENT_DATE_PATTERN = "yyyy-MM-dd";
	
	public static String getCurrentTime() {
		return DateFormatUtils.format(new Date(), CURRENT_TIME_PATTERN);
	}
	
	public static String getCurrentDate() {
		return DateFormatUtils.format(new Date(), CURRENT_DATE_PATTERN);
	}   
	
	public static String getUUID(){		
      return UUID.randomUUID().toString().replace("-", "").toUpperCase();
	}
	
	public static void main(String[] args) {
		System.out.println(getCurrentTime());
		System.out.println(getCurrentDate());		
	}
	
	public static String getIpAddr(HttpServletRequest request) {
	       String ip = request.getHeader("x-forwarded-for");
	       if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
	           ip = request.getHeader("Proxy-Client-IP");
	       }
	       if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
	           ip = request.getHeader("WL-Proxy-Client-IP");
	       }
	       if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
	           ip = request.getRemoteAddr();
	       }
	       return ip;
	   } 

}
